package inits

import (
	"dache-server/basic/config"
	"fmt"
	"github.com/elastic/go-elasticsearch/v7"
	"log"
)

func InitEs() {
	var err error
	data := config.Appconf.ElasticSearch
	addr := fmt.Sprintf("http://%s:%d", data.Host, data.Port)

	cfg := elasticsearch.Config{
		Addresses: []string{
			addr,
		},
		// ...
	}
	config.Es, err = elasticsearch.NewClient(cfg)
	if err != nil {
		panic("es连接失败")
	}
	log.Println("es连接成功")
}
